﻿using System.Collections.Generic;

namespace Bricks.Validation
{
    
    /// <summary>
    /// 
    /// </summary>
    public class ValidationResult
    {

        /// <summary>
        /// 
        /// </summary>
        private readonly string _message;

        /// <summary>
        /// 
        /// </summary>
        private readonly string _key;

        /// <summary>
        /// 
        /// </summary>
        private readonly string _tag;

        /// <summary>
        /// 
        /// </summary>
        private readonly object _target;

        /// <summary>
        /// 
        /// </summary>
        private readonly IValidatorFacade _validator;

        /// <summary>
        /// 
        /// </summary>
        private readonly IEnumerable<ValidationResult> _nestedValidationResults;

        /// <summary>
        /// 
        /// </summary>
        private static readonly IEnumerable<ValidationResult> NoNestedValidationResults = new ValidationResult[] { };

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="target"></param>
        /// <param name="key"></param>
        /// <param name="tag"></param>
        /// <param name="validator"></param>
        public ValidationResult(string message, object target, string key, string tag, IValidatorFacade validator) :
            this(message, target, key, tag, validator, NoNestedValidationResults)
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="target"></param>
        /// <param name="key"></param>
        /// <param name="tag"></param>
        /// <param name="validator"></param>
        /// <param name="nestedValidationResults"></param>
        public ValidationResult(string message, object target, string key, string tag, IValidatorFacade validator, IEnumerable<ValidationResult> nestedValidationResults)
        {
            _message = message;

            _key = key;

            _target = target;

            _tag = tag;

            _validator = validator;

            _nestedValidationResults = nestedValidationResults;
        }

        /// <summary>
        /// 
        /// </summary>
        public string Key
        {
            get { return _key; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Message
        {
            get { return _message; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Tag
        {
            get { return _tag; }
        }

        /// <summary>
        /// 
        /// </summary>
        public object Target
        {
            get { return _target; }
        }

        /// <summary>
        /// 
        /// </summary>
        public IValidatorFacade Validator
        {
            get { return _validator; }
        }

        /// <summary>
        /// 
        /// </summary>
        public IEnumerable<ValidationResult> NestedValidationResults
        {
            get { return _nestedValidationResults; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return _message;
        }
    }
}
